<template lang="html">
  <el-dialog :id="target"   :title="dialoginfo.title"
             @open="listenopen()"
             :append-to-body="true"
             top="60px"
             width="50%"
             @close="close" :visible="dialoginfo.show">
    <el-form size="mini"  :model="dialoginfo.data" ref="dialoginfo" label-position="left">
      <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                    prop="title" label="标题" :label-width="formLabelWidth">
        <el-input  v-model="dialoginfo.data.title" auto-complete="off" clearable/>
      </el-form-item>
      <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                    prop="author" label="作者" :label-width="formLabelWidth">
        <el-input type="text" v-model="dialoginfo.data.author" auto-complete="off" clearable></el-input>
      </el-form-item>
      <el-form-item v-if="dialoginfo.data.id!=null" :rules="[
                      { required: true, message: '不能为空'}
                    ]" prop="state" label="状态" :label-width="formLabelWidth">
        <el-select clearable v-model.trim="dialoginfo.data.state" style="width: 100%;" placeholder="请选择">
          <el-option label="待审核" :value="0"></el-option>
          <el-option label="已审核" :value="1"></el-option>
          <el-option label="已禁用" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :rules="[{ required: true, message: '不能为空'}]"
                    prop="descript" label="简介" :label-width="formLabelWidth">
        <el-input type="text" v-model="dialoginfo.data.descript" auto-complete="off" clearable></el-input>
      </el-form-item>
      <el-form-item label="内容" required :label-width="formLabelWidth">
        <wangEdit :dialoginfo="dialoginfo"></wangEdit>
      </el-form-item>
      <el-row>
        <el-form-item style="text-align: right">
          <el-button size="mini" @click="dialoginfo.show = false">取 消</el-button>
          <el-button size="mini" type="primary" @click="toAdd('dialoginfo')">保 存</el-button>
        </el-form-item>
      </el-row>
    </el-form>
  </el-dialog>
</template>
<script>

   import wangEdit from "@/components/modules/sysManagement/information/wangEdit";
  export default {
    inject: ["reload"],
    components: {
      "wangEdit":wangEdit
    },
    data() {
      return {
        target: "userAssetadjust",
        formLabelWidth: '104px'
      }
    },
    props: ['dialoginfo'],
    methods: {
      listenopen() {
        if (this.isadd && this.$refs['dialoginfo'] != null) {
          this.$refs['dialoginfo'].resetFields();
        }
      },
      close() {
        this.$emit('changedialogshow');
      },
      toAdd(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$store.commit("saveLoadingMap", {"target": this.dialoginfo.url,id:this.target});
            this.proAPI.postJson(this.dialoginfo.url, this.dialoginfo.data).then((res) => {
              this.$message.success({
                "message": res.message
              })
              setTimeout(()=>{
                this.reload();
              },1000)
            });
          } else {
            return false;
          }
        });
      }
    },
    updated() {
    },
    mounted() {

    },
  };
</script>
<style lang="css">
  #userage >>> .el-input-number .el-input__inner {
    text-align: left;
  }

  #userBaseInfoEdit >>> .el-dialog__body {
    padding: 15px 20px;
    color: #606266;
    font-size: 14px;
  }
</style>
